<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
            <el-breadcrumb-item :to="{ path: '/sys-admin' }">
                <i class="el-icon-s-promotion"></i> 后台管理
            </el-breadcrumb-item>
            <el-breadcrumb-item>品牌列表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-table :data="tableData" stripe style="width: 100%" border>
            <el-table-column prop="name" label="姓名" align="center" width="230"></el-table-column>
            <el-table-column prop="pinyin" header-align="center" label="拼音"></el-table-column>
            <el-table-column prop="logo" header-align="center" label="拼音"></el-table-column>
            <el-table-column prop="description" header-align="center" label="关键字"></el-table-column>
            <el-table-column prop="keywords" header-align="center" label="关键字"></el-table-column>
            <el-table-column prop="sort" align="center" label="排序" width="100"></el-table-column>
            <el-table-column label="是否启用" prop="enable">
                <el-switch
                        v-model="tableData.enable"
                        :active-value="1"
                        :inactive-value="0"
                        active-color="#13ce66"
                        inactive-color="#999">
                </el-switch>
            </el-table-column>
            <el-table-column align="center" label="操作" width="100">
                <template slot-scope="scope">
                    <el-button type="primary" icon="el-icon-edit" size="mini" circle @click="handleEdit(scope.row)"></el-button>
                    <el-button type="danger" icon="el-icon-delete" size="mini" circle @click="handleDelete(scope.row)"></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
    export default {
        data() {
            return {
                tableData: [{
                    name: '王小虎',
                    pinyin: '上海市普陀区金沙江路 1518 弄',
                    keywords:'',
                    logo:'',
                    description:'',
                    sort:'',
                    enable:''
                }]
            }
        },
        methods:{
            loadBrandList(){
                let url = "http://localhost:9080/brand/list";
                console.log('loadBrandList()');
                this.axios
                    .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
                    .get(url).then((response) =>{
                    this.tableData = response.data.data;
                })
            },
            handleDelete(brand){
                this.$confirm('此操作将永久删除'+brand.name+', 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let url = "http://localhost:9080/brand/deleteById?id="+brand.id;
                    this.axios.get(url).then((response)=>{
                        let responseBody = response.data;
                        if(responseBody.state!=20000){
                            this.$message.error(responseBody.message);
                        }
                        this.loadBrandList();
                    })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            handleEdit(attrTemp){
                let url = "http://localhost:9080/brand/edit";
            }
        },
        created(){
            console.log('created()');
        },
        mounted(){
            console.log('mounted()');
            this.loadBrandList();
        }
    }
</script>

<style scoped>

</style>